<?php
namespace App\Services\Admin;

use App\Jobs\Fun;
use App\Models\User\UserModel;
use App\Models\UserStaffModel;
use App\Repositories\Admin\CompanyRepository;
use App\Repositories\Admin\JobCompanyRepository;
use App\Repositories\Admin\JobRepository;
use App\Repositories\Admin\JobStaffRepository;
use App\Repositories\Admin\UserRepository;

class JobCompanyService
{
    private $service;
    private $company;
    private $job;
    private $user;

    public function __construct()
    {
        $this->service = new JobCompanyRepository();
        $this->company = new CompanyRepository();
       $this->job = new JobRepository();
      //  $this->user = new UserRepository();
    }

    public function getIndex()
    {
        $models = $this->service->getIndexList();
        if (!count($models)) { return ''; }
        foreach ($models as $model) {
            $company = $this->company->getShowOneByUid($model->cid);
            $job = $this->job->getShowOne($model->job);
            $model->comName = $company ? $company->name : '测试公司';
            $model->jobName = $job ? $job->name : '测试岗位';
        }
        return $models;
    }

    /**
     * APP岗位推荐
     */
    public function getAppJobComs()
    {
        $models = $this->service->getAppJobComs();
        if (!count($models)) { return []; }
        $dataArr =[];
        foreach ($models as $k=>$model) {


            $job = $this->job->getShowOne($model->job);
            $user =UserModel::getinfo($model->cid);


            $dataArr[$k]['id'] =$model->id;
            $dataArr[$k]['jobName'] = $job ? $job->name : '岗位';
            $dataArr[$k]['num'] =$model->num;

            $dataArr[$k]['age_range'] =$model->age_range;//年龄
            $dataArr[$k]['education'] = UserStaffModel::educationTo($model->education);//学历

            $dataArr[$k]['uname'] = $user['name'];
            $dataArr[$k]['head'] = $user['head'];

            $dataArr[$k]['company_name'] =$model->company_name;///公司名称

            $dataArr[$k]['emolument'] =$model->emolument;   ///薪水
            $dataArr[$k]['num'] =$model->num;
            $dataArr[$k]['address'] =$model->address;  //地址

            /* $com = $this->company->getShowOne($model->cid);
            $user = $this->user->getShowOne($model->cid);
            $dataArr[$k]['jobName'] = $job ? $job->name : '测试岗位';
            $dataArr[$k]['comName'] = $com ? $job->name : '测试公司';
            $dataArr[$k]['img'] = Fun::pImg( $user->head);
            $dataArr[$k]['uname'] = $user ? $user->name : '发布人';
            $dataArr[$k]['emolument'] =$model->emolument;
            $dataArr[$k]['cityName'] = $model->address;
            $dataArr[$k]['workYear'] = $model->work_year;
            $dataArr[$k]['id'] = $model->id;
            */

        }
        return $dataArr;
    }

//    /**
//     * 待删除
//     */
//    public function getIndexByCid($uid)
//    {
//        $models = $this->service->getIndexByCid($uid);
//        if (!count($models)) { return array(); }
//        $resJob = new JobRepository();
//        $resTemp = new JobStaffRepository();
//        $lastDay = strtotime(date('Ymd',time()).' 000000') ; //当前时间
//        foreach ($models as $model) {
//            $resJobOne = $resJob->getShowOne($model->job);
//            $model->jobName = $resJobOne ? $resJobOne->name : '';
//            if ($resTemp->getSuccessOne($model->id)) {
//                $model->statusName = '已完成';
//            }
//            if ($resTemp->getIndexByCom($model->id)) {
//                $model->statusName = '面试中';
//            }
//            else if ($model->created_at > $lastDay) {
//                $model->statusName = '最新发布';
//            }
//            else {
//                $model->statusName = '已发布';
//            }
//        }
//        return $models;
//    }

    /**
     * 我的发布里面招聘
     */
    public function getJobsByCid($uid,$page)
    {
        return $this->service->getAppJobsByCid($uid,$page);
    }

    public function add($data)
    {
        return $this->service->setAdd($data);
    }

    public function modify($data,$id)
    {
        return $this->service->setModify($data,$id);
    }

    public function getOne($id)
    {
        return $this->service->getShowOne($id);
    }
}